<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	request.setCharacterEncoding("UTF-8");
	String cp = request.getContextPath(); 
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="<%=cp%>/data/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript">

$(document).ready(function(){
	$("#sendButton").click(function(){
		
		var params = "userName=" +$("#userName").val() + "&userAge=" +$('#userAge').val();
		
		$.ajax({
			type:"post",
			url:"a2_ok.jsp",
			data:params,
			success:function(args){
				$('#resultDIV').html(args);
			},
			beforeSend:showRequest,
			error: function(e){
				alert(e.responseText);
			}
		});
	});
	
	function showRequest(){
		
		var flag = true;
		if(!$("#userName").val()){
			
			alert("제목을 입력하세요...");
			$("#userName").focus();
			flag = false;
		}else if(!$("#userAge").val()){
			alert("나이를 입력하세요...");
			$("#userAge").focus();
			flag = false;
		}
		
		return flag;
	}
});
</script>
</head>
<body>

이름 : <input type="text" id="userName"/><br/>
나이 : <input type="text" id="userAge"/><br/>
<input type="button" value="보내기" id="sendButton"/>
<div id="resultDIV"></div>

</body>
</html>